package com.stx.xhb.customwaterview;

import ohos.app.Context;

import java.util.Random;

/**
 * @author: xiaohaibin.
 * @time: 2018/1/5
 * @mail:xhb_199409@163.com
 * @github:https://github.com/xiaohaibin
 * @describe: 工具类
 */

public class Utils {

    private static Random random = new Random();

    /**
     * Dp 2 px int
     *
     * @param context context
     * @param values  values
     * @return the int
     */
    public static int dp2px(Context context, int values) {
        return (int) (context.getResourceManager().getDeviceCapability().screenDensity / 160 * values);
    }

    /**
     * Gets random *
     *
     * @param lower lower
     * @param upper upper
     * @return the random
     */
    public static float getRandom(float lower, float upper) {
        float min = Math.min(lower, upper);
        float max = Math.max(lower, upper);
        return getRandom(max - min) + min;
    }

    /**
     * Gets random *
     *
     * @param upper upper
     * @return the random
     */
    public static float getRandom(float upper) {
        return random.nextFloat() * upper;
    }


    /**
     * Gets random *
     *
     * @param upper upper
     * @return the random
     */
    public static int getRandom(int upper) {
        return random.nextInt(upper);
    }
}
